package rullekake.facade;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import rullekake.entities.Faculty;
import rullekake.entities.Institution;

/**
 * Utvider AbstractFacade for Faculty.
 * Tar seg av peristence for Faculty-objekter
 *
 */
@Stateless
public class FacultyFacade extends AbstractFacade<Faculty> {
    @PersistenceContext(unitName = "SystemeringPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public FacultyFacade() {
        super(Faculty.class);
    }

    /**
     * Finner alle fakulteter som er knytt til en gitt institutsjon.
     * @param institution
     * @return liste med fakulteter
     */

    public List<Faculty> findFacultiesByInstitution(Institution institution) {
        javax.persistence.Query q = getEntityManager().createNamedQuery("Faculty.findByInstitution");
        q.setParameter("institution", institution);
        return q.getResultList();
    }

}
